$(document).ready(function() {
	
	$('.preview_link').live('click',function(){
		var self = $(this),
			url = self.attr('data-href'), 
			form = self.closest('form'),
			target_form = form.attr('target'),
			iframe = '<iframe name="output_frame" src="#" id="output_frame" width="1024" height="400"></iframe>',
			iframe_name = $(iframe).attr('name');
			iframe_id = $(iframe).attr('id');
			dialog = $("#iframe-"+iframe_name);
		//Создание диалога
		dialog.dialog({
	        autoOpen: false,
	        width: "1050",
	        modal: true,
	        position: "top",
	        resizable: true,
	        autoResize: true,
	        open:function(){
				//Запихиваем Iframe в диалог
				if(dialog.find("iframe").size()==0){
					dialog.append(iframe);
	    		}
				//Сабмитим форму в iframe
				form.attr('target',iframe_name).attr('action',url).submit();
				var e = $('#'+iframe_id);
				e.load(function(){
					var content = $(this).contents().find("#wrapper"),
						height = (content.length) ? content.height() : 500;
					$(this).attr( 'height',height );
				});
				form.removeAttr('target').attr('action','');
	        },
	        buttons : {
				"Закрыть" : function() {
					$(this).dialog("close");
				},
			}
		
		});
		dialog.dialog("open");
		return false;
	});
	
	
});